<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login Page with Frontend Captcha</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: Arial, sans-serif;
      background-image: url('img/login.jpg');
      background-size: cover;
      background-position: center;
      height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .login-container {
      background: rgba(255, 255, 255, 0.8);
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
      text-align: center;
    }

    input {
      width: 100%;
      padding: 10px;
      margin: 8px 0;
      box-sizing: border-box;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    #captchaImageContainer {
      margin-top: 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    #captchaImage {
      max-width: 100%;
      height: auto;
      cursor: pointer;
    }

    #refreshText {
      cursor: pointer;
      color: blue;
      margin-left: 5px;
    }

    button {
      background-color: #4CAF50;
      color: white;
      padding: 10px 20px;
      margin: 8px 0;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    button:hover {
      background-color: #45a049;
    }

    #registerLink {
      color: blue;
      text-decoration: none;
      margin-top: 10px;
      display: block;
    }
  </style>
</head>
<body>

<div class="login-container">
  <h2>登录</h2>
  <form action="/user/login" method="post">
    <label for="phone">手机号:</label>
    <input type="text" id="phone" name="phone" required>

    <label for="password">密码:</label>
    <input type="password" id="password" name="password" required>

    <label for="captcha">验证码:</label>
    <input type="text" id="captcha" name="captcha" required>
    

    <div id="captchaImageContainer">

      <img id="captchaImage" src="/user/captcha" alt="Captcha">
      <span id="refreshText" onclick="refreshCaptcha()">获取验证码</span>
    </div>

    <button type="submit">Login</button>

    <a href="register.html" id="registerLink">还没有账号？点我注册</a>
  </form>
</div>
<script>
  function refreshCaptcha() {
    var captchaImage = document.getElementById('captchaImage');
    var timestamp = Date.now(); // 获取当前时间戳
    captchaImage.src = '/user/captcha?' + timestamp; // 添加时间戳参数强制刷新验证码
  }
</script>

</body>
</html>
